﻿using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using CodeContrib.Data.Entity;

namespace CodeContrib.Tests.Data.Entity
{
	public class CustomTreeContext : DbContext
	{
		public DbSet<CustomTree> CustomTrees { get; set; }
		public DbSet<CustomTreeNode> CustomTreeNodes { get; set; }
		
		public CustomTreeContext(string nameOrConnectionString)
			: base(nameOrConnectionString)
		{
			Configuration.LazyLoadingEnabled = true;
		}

		protected override void OnModelCreating(DbModelBuilder modelBuilder)
		{
			base.OnModelCreating(modelBuilder);

			modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
			modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

			modelBuilder.Entity<CustomTree>().HasMany(CustomTree.PropertyAccessExpressions.TreeNodes);
		}
	}
}
